/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#ifndef INCLUDE_SHADER_RAY
#define INCLUDE_SHADER_RAY


#define DEF_OBTYPE_Mesh           0
#define DEF_OBTYPE_ParallelLight  1
#define DEF_OBTYPE_PointLight     2
#define DEF_OBTYPE_SpotLight      3

#define DEF_RY_InstanceBitSize    16
#define DEF_RY_InstanceBitFlag    0x0000ffff




#ifdef __cplusplus

#include <basic_def.h>

// GLSL Type
using uint = unsigned int;
using uint64_t = uint64;

#define inout




#else

#define Inline

#define M_PI 3.1415926535

#extension GL_EXT_scalar_block_layout : enable
#extension GL_EXT_buffer_reference2 : require
#extension GL_EXT_shader_16bit_storage : require

#define EngineAPI_EXPORT 

#endif


#define DEF_renderLayer_composite	0
#define DEF_renderLayer_albedo		1
#define DEF_renderLayer_depth		2
#define DEF_renderLayer_normal		3
#define DEF_renderLayer_illuminate	4
#define DEF_renderLayer_shadow		5

#define DEF_RF_PM_composite		65536
#define DEF_RF_PM_albedo		131072
#define DEF_RF_PM_depth			262144
#define DEF_RF_PM_normal		524288
#define DEF_RF_PM_illuminate	1048576
#define DEF_RF_PM_shadow		2097152
#define DEF_RF_PM_PreviewFlag	2147483648
#define DEF_RF_PM_all			4294901760

#define DEF_RF_RL_composite		1
#define DEF_RF_PL_albedo		2
#define DEF_RF_PL_depth			4
#define DEF_RF_PL_normal		8
#define DEF_RF_PL_illuminate	16
#define DEF_RF_PL_shadow		32
#define DEF_RF_PL_all			4294901760


#define DEF_RF_PM					( (renderFrame.m_OutLayer_PreviewMode) & 2147418112 )
#define DEF_RF_RenderLayers(Value)	((0x0000ffff & renderFrame.m_OutLayer_PreviewMode) & (Value))
#define DEF_RF_isPreview			(renderFrame.m_OutLayer_PreviewMode & DEF_RF_PM_PreviewFlag)



//物体遮罩模式
#define DEF_Mask_None        0
#define DEF_Mask_Indirect    1
#define DEF_Mask_Discard     2
#define DEF_Mask_Shadow      3






struct EngineAPI_EXPORT S_Vert {
	vec3 vert;
	vec3 normal;
	vec2 UV;
};


struct EngineAPI_EXPORT S_ShaderMaterialTexture {
	int m_colorTex;
	int m_emissionTex;
	int m_reflectTex;
	int m_roughnessTex;
	int m_alphaTex;
};





#define DEF_SurfaceType_Reflect		0x00000001
#define DEF_SurfaceType_Refract		0x00000002
#define DEF_SurfaceType_Emission	0x00000004
#define DEF_SurfaceType_Faceforward	0x00000010
#define DEF_SurfaceType_Entity		0x00000100

struct S_Ray {
	vec3 Color;
	vec3 Normal;
	vec3 Diffuse;

	uint Depth;
	uint RayType;
	uint Ligth_Type_ID;

	float	Dis;
	float	irradiance;
	float	Alpha;
	float	LigthDis;
	uint	LigthMask;
	uint	SurfaceType;

};

struct S_SceneDataCall {
	vec3 Vert;
	vec3 Normal;
	vec3 rayDir;
	vec3 ligthDir;
	vec3 barycentrics;

	//输出颜色
	vec3 Color;

	//uint InstanceID;
	//全局ID索引
	uint InstanceIndex;
	uint PrimitiveIndex;
	//uint GeometryIndex;

	float irradiance;
	float reflect;
	float roughness;
	float transmission;
	float alpha;
	//float dis;
	// [8:表面类型m, 8:表面类型, 16:材质ID]
	uint   MaterialID;
	//uint  Depth;
	//场景ID 遮挡类型
};



struct EngineAPI_EXPORT S_Geom {
	vec3 vert;
	
	vec3 boundOffset;
	vec3 boundSize;

	vec3 uv;
	//相对于上一层UV索引的偏移
	uvec3 uvIndexOffset012;
	uvec3 uvIndexOffset345;
	uvec3 uvIndexOffset678;

	//纹理层数和UV内存偏移
	uvec3 uvLayerAndOffset;
	
};



struct EngineAPI_EXPORT GLSL_RenderFrame {
	uint64_t m_Address_RtOb;

	uvec2	m_ViewSize;
	uint	m_Frame;
	uint	m_ParallelLightNum;
	uint	m_PointLightNum;
	uint	m_SpotLightNum;
	uint	m_AreaLightNum;
	
	uint	m_BouncesNum;
	uint	m_LigthSamples;
	
	uint	m_SamplesNum;

	int m_world_ShaderID;

	int m_ViewOffset_X;
	int m_ViewOffset_Y;

	float m_MaxZ;

	uint m_OutLayer_PreviewMode;
	uint m_SceneMask_ObMask;
};




#endif


